/**
 * 
 */
package com.neal.web.validation;

import org.springframework.binding.validation.ValidationContext;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import com.neal.domain.Plane;
import com.neal.utils.MessageUtils;

/**
 * @author Neal
 * @version 1.0
 * @description
 */
@Component
public class PlaneValidator implements Validator {

	public void validateShowPlane(Plane plane, ValidationContext validationContext) {
		
		if (plane.getName().length() < 5) {
			MessageUtils.addMessageToValidator(validationContext, "name", "plane.name.too.min");
		}
		if (plane.getFlyDate1() == null) {
			MessageUtils.addMessageToValidator(validationContext, "flyDate1", "can't null");
		}

		if (plane.getFlyDate2() == null) {
			MessageUtils.addMessageToValidator(validationContext, "flyDate2", "can't null", "不能空");
		}

		if (plane.getFlyDate1() != null && plane.getFlyDate2() != null
				&& plane.getFlyDate1().after(plane.getFlyDate2())) {
			MessageUtils.addMessageToValidator(validationContext, "flyDate1",
					"Check A must be before B","flyDate1","flyDate2");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	@Override
	public boolean supports(Class<?> clazz) {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.validation.Validator#validate(java.lang.Object,
	 * org.springframework.validation.Errors)
	 */
	@Override
	public void validate(Object target, Errors errors) {
		// TODO Auto-generated method stub

	}
}
